package st.business.tepth.business.visitor.visitorwork.work.detail;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.visitor.visitorwork.entity.WorkDetailBean;
import st.business.tepth.config.ItemFields;
import st.shadow.library.ui.recycler.MultipleItemEntity;

/**
 * @author zhangyu
 * @date 2019/6/6
 */
public class MaintainAdapter extends BaseMultiItemQuickAdapter<MultipleItemEntity,
        BaseViewHolder> {
    public static final int TYPE_1 = 1;
    public static final int TYPE_2 = 2;
    public static final int TYPE_3 = 3;

    public MaintainAdapter(List<MultipleItemEntity> data) {
        super(data);
        addItemType(TYPE_1, R.layout.item_work_maintain_read_only_type_1);
        addItemType(TYPE_2, R.layout.item_work_maintain_read_only_type_2);
        addItemType(TYPE_3, R.layout.item_work_maintain_read_only_type_3);
    }

    @Override
    protected void convert(BaseViewHolder viewHolder, MultipleItemEntity entity) {
        switch (entity.getItemType()) {
            case TYPE_1:
                viewHolder.setText(R.id.tv_content,
                        (CharSequence) entity.getField("content"));
                viewHolder.addOnClickListener(R.id.tv_finish_check);
                break;
            case TYPE_2:
                break;
            case TYPE_3:
                WorkDetailBean.RepairBean.ProgramBean programBean =
                        entity.getField(ItemFields.ITEM_OBJ);
                WorkDetailBean.RepairBean.ProgramBean.PartBean partBean =
                        programBean.getPart();
                WorkDetailBean.RepairBean.ProgramBean.MaterialBean materialBean =
                        programBean.getMaterial();
                viewHolder.setText(R.id.tv_diagnose,
                        "诊断:" + programBean.getDiagnose());
                viewHolder.setText(R.id.tv_person,
                        "作业人:" + programBean.getPerson());
                viewHolder.setText(R.id.tv_action,
                        "动作:" + programBean.getAction());
                viewHolder.setText(R.id.tv_part,
                        "零部件:" + (partBean == null ? "无" : partBean.getPart()));
                viewHolder.setText(R.id.tv_part_code,
                        "零部件编码:" + (partBean == null ? "无" : partBean.getPartNo()));
                viewHolder.setText(R.id.tv_part_supply,
                        "零部件供应商:" + (partBean == null ? "无" : partBean.getPartSupply()));
                viewHolder.setText(R.id.tv_material,
                        "耗材:" + (materialBean == null ? "无" : materialBean.getMaterial()));
                viewHolder.setText(R.id.tv_materials_code,
                        "耗材编码:" + (materialBean == null ? "无" : materialBean.getMaterialNo()));
                viewHolder.setText(R.id.tv_materials_count,
                        "耗材用量:" + (materialBean == null ? "无"
                                : (materialBean.getMaterialCount() + materialBean.getMaterialUnit())));
                break;
        }
    }
}
